<?php
/*
$Id: qbi_products.php,v 2.10 2005/05/08 al Exp $

Quickbooks Import QBI
contribution for osCommerce
ver 2.10 May 8, 2005
(c) 2005 Adam Liberman
www.libermansound.com
info@libermansound.com
Please use the osC forum for support.
Released under the GNU General Public License

    This file is part of Quickbooks Import QBI.

    Quickbooks Import QBI is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    Quickbooks Import QBI is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Quickbooks Import QBI; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

require('includes/application_top.php');
require(DIR_WS_LANGUAGES . $language . '/qbi_general.php');
// Now read new configuration
require_once(DIR_WS_INCLUDES . 'qbi_version.php');
require_once(DIR_WS_INCLUDES . 'qbi_definitions.php');
require_once(DIR_WS_FUNCTIONS . 'qbi_functions.php');
require_once(DIR_WS_CLASSES . 'qbi_classes.php');
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<link rel="stylesheet" type="text/css" href="includes/qbi_styles.css">
<script type="text/javascript" src="includes/general.js"></script>
<script type="text/javascript" src="includes/menu.js"></script>
<script type="text/javascript"><!--
popUpWin=0;

function popUpWindow(URLStr, left, top, width, height){

  if(popUpWin)

  {

    if(!popUpWin.closed) popUpWin.close();

  }

  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');

}
//--></script>
</head>
<body bgcolor="#FFFFFF">
<div id="spiffycalendar" class="text"></div>
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr>
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
    </table></td>
<!-- body_text //-->
    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
            <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td>
<table>
<?php
$filenames=array("qbi_input/items.iif","qbi_input/items.IIF","qbi_input/lists.iif","qbi_input/lists.IIF");
if (!isset($stage)) {
  foreach($filenames as $filename) {
    if (file_exists($filename)) {
      $filefound=1;
	  break;
    }
  }
  if ($filefound==1) { ?>
    <form action="<?php echo $_SERVER[PHP_SELF] ?>" method="post" name="additems">

    <input name="file_name" type="hidden" value="<?php echo $filename ?>" />
    <input name="stage" type="hidden" value="processfile" /> <?php
    echo SETUP_FILE_FOUND1." $filename".SETUP_FILE_FOUND2; ?>
    <input name="submitfile" type="submit" id="submitfile" value="<?php echo SETUP_FILE_BUTTON ?>" />
    </form><br><br> <?php
  } else {
    echo SETUP_FILE_MISSING;
  }
  item_group_list();
} elseif (isset($stage) AND $stage=="processfile") {

// Open, read, and parse iif to import QB items
  $handle = fopen($file_name, "rb");
  unset($iif_refnum);
  echo '<table class="lists">';
  while (($iifread=fgetcsv($handle, 512, "\t"))!==FALSE) {
    if ($iifread[0]=="!INVITEM") {
      $iifheader=$iifread;
      echo "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
      echo '<tr><th class="colhead">'.PROD_ITEMS."</th><th></th><th></th><th></th></tr>";
      echo '<tr><th class="colhead">'.SETUP_NAME.'</th><th class="colhead">'.SETUP_DESC.'</th><th class="colhead">'.SETUP_ACCT.'</th><th class="colhead">'.SETUP_ACTION."</th></tr>";
    } elseif ($iifread[0]=="INVITEM") {
      $iifdetail=$iifread;
      $iifitem=arraycombine($iifheader,$iifdetail);
      if (($iifitem["INVITEMTYPE"]=="INVENTORY" OR $iifitem["INVITEMTYPE"]=="SERV" OR $iifitem["INVITEMTYPE"]=="PART" OR $iifitem["INVITEMTYPE"]=="DISC" OR $iifitem["INVITEMTYPE"]=="OTHC") AND ($iifitem["HIDDEN"]=="N")) {
        $iif_refnum[]=$iifitem["REFNUM"];
        item_process($iifitem["NAME"],$iifitem["REFNUM"],$iifitem["DESC"],$iifitem["ACCNT"],$iifitem["PRICE"],$iifitem["INVITEMTYPE"]);
      } elseif (($iifitem["INVITEMTYPE"]=="STAX") AND ($iifitem["HIDDEN"]=="N")) {
        tax_group_process($handle);
      } elseif (($iifitem["INVITEMTYPE"]=="GRP") AND ($iifitem["HIDDEN"]=="N")) {
        group_process($iifitem["NAME"],$iifitem["REFNUM"],$iifitem["DESC"],$iifitem["TOPRINT"],$handle,$iifheader);
      }
    }
  }
  if (isset($iif_refnum) AND count($iif_refnum)>=1) {
    item_delete($iif_refnum);
	echo SETUP_SUCCESS."<br>";
  } else {
	echo SETUP_FAIL."<br>";
  }
  echo "</table>";
  fclose($handle);
}
?>
</form></table>
          </tr>
        </table></td>
      </tr>

    </table></td>
<!-- body_text_eof //-->
  </tr>

</table></form>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
